<template>
  <a-modal v-model:visible="visible" :title="id ? '编辑采集' : '添加采集'" :footer="null">
    <div class="py-8">
      <this-form @finished="finished" ref="formRef" />
    </div>
  </a-modal>
</template>
  <script lang="ts">
import { message } from 'ant-design-vue';
import { defineComponent, ref, nextTick } from 'vue';
import thisForm from './hub-form.vue';
import { defHttp } from '/@/utils/http/axios';

export default defineComponent({
  components: { thisForm },
  setup(props, { emit }) {
    const visible = ref<boolean>(false);
    let id = ref();
    const formRef = ref<any>();

    const open = (hub) => {
      id.value = hub.id ?? null;
      visible.value = true;
      nextTick(() => {
        console.log(hub.dutId);
        formRef.value.setForm(hub);
      });
    };

    const finished = (params) => {
      let url;
      if (id.value) {
        params.id = id.value;
        url = '/gather-device/update';
      } else {
        url = '/gather-device/add';
      }

      defHttp
        .post({
          url,
          params,
        })
        .then((res) => {
          if (res.rst) {
            message.success('操作成功');
            emit('updated');
            visible.value = false;
          } else {
            message.error(res.data);
          }
        });
    };

    return {
      visible,
      finished,
      open,
      id,
      formRef,
    };
  },
});
</script>
  
  